<?
if(strpos($_REQUEST['act'],"Excel")!==false){
	require_once 'class/PHPExcel.php'; 
	require_once('class/PHPExcel/Writer/Excel2007.php');  	
	$objExcel = new PHPExcel();   
	$objExcel->setActiveSheetIndex(0);       
	$objActSheet = $objExcel->getActiveSheet();       	
	$objWriter = new PHPExcel_Writer_Excel5($objExcel);   
	$n=1; 
	switch($_REQUEST['act']){
		/*销售报表导出*/
		case "orderReportExcel":
			$objActSheet->getColumnDimension('A')->setAutoSize(true); 
			$objActSheet->getColumnDimension('B')->setAutoSize(true);  
			$objActSheet->getColumnDimension('C')->setAutoSize(true);  
			$objActSheet->getColumnDimension('D')->setAutoSize(true);  
			$objActSheet->getColumnDimension('E')->setAutoSize(true);
			$objActSheet->getColumnDimension('F')->setAutoSize(true);  
			$objActSheet->getColumnDimension('G')->setAutoSize(true);  
			$objActSheet->getColumnDimension('H')->setAutoSize(true);
            $objActSheet->getColumnDimension('I')->setAutoSize(true);
            $objActSheet->getColumnDimension('J')->setAutoSize(true);
			
			$objActSheet->setCellValue('A'.$n, $titleT[$by]);    
			$objActSheet->setCellValue('B'.$n, "订单数量");  
			$objActSheet->setCellValue('C'.$n, "门票数量");
			$objActSheet->setCellValue('D'.$n, "金额");
			$objActSheet->setCellValue('E'.$n, "账户余额");
			$objActSheet->setCellValue('F'.$n, "支付宝");
			$objActSheet->setCellValue('G'.$n, "供应额度");
			$objActSheet->setCellValue('H'.$n, "产品自销");
            $objActSheet->setCellValue('I'.$n, "现场支付");
            $objActSheet->setCellValue('J'.$n, "微信支付");
            $objActSheet->setCellValue('K'.$n, "银联支付");
			$objActSheet->getStyle('A'.$n)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			foreach($r as $lid=>$row){
				$n++;
				$objActSheet->setCellValue('A'.$n, 		$row['title'] );    
				$objActSheet->setCellValue('B'.$n, abs($row['order']) );
				$objActSheet->setCellValue('C'.$n, abs($row['tnum'] ) );
				$objActSheet->setCellValue('D'.$n, abs($row['money']/100) );
				$objActSheet->setCellValue('E'.$n, abs($row['pmode0']/100) );    
				$objActSheet->setCellValue('F'.$n, abs($row['pmode1']/100) );
				$objActSheet->setCellValue('G'.$n, abs($row['pmode2']/100) );
				$objActSheet->setCellValue('H'.$n, abs($row['pmode3']/100) );
                $objActSheet->setCellValue('I'.$n, abs($row['pmode4']/100) );
                $objActSheet->setCellValue('J'.$n, abs($row['pmode5']/100) );
                $objActSheet->setCellValue('K'.$n, abs($row['pmode7']/100) );
				//输出样式
				$objActSheet->getStyle('A'.$n)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); 
			}
			$filename=date('Ymd').'销售报表';
		
		break;
		/*分销账单详细导出excel*/
		case "fsettle1Excel":
			$objActSheet->getColumnDimension('A')->setAutoSize(true); 
			$objActSheet->getColumnDimension('B')->setAutoSize(true);  
			$objActSheet->getColumnDimension('C')->setAutoSize(true);  
			$objActSheet->getColumnDimension('D')->setAutoSize(true);  
			$objActSheet->getColumnDimension('E')->setAutoSize(true);
			$objActSheet->getColumnDimension('F')->setAutoSize(true);  
			$objActSheet->getColumnDimension('G')->setAutoSize(true);  
			$objActSheet->getColumnDimension('H')->setAutoSize(true);
			
			$objActSheet->setCellValue('A'.$n, "订单号");    
			$objActSheet->setCellValue('B'.$n, "产品名称");  
			$objActSheet->setCellValue('C'.$n, "预订日期");
			$objActSheet->setCellValue('D'.$n, "使用日期");
			$objActSheet->setCellValue('E'.$n, "取票人信息");
			$objActSheet->setCellValue('F'.$n, "结算价（元）");
			$objActSheet->setCellValue('G'.$n, "人数");
			$objActSheet->setCellValue('H'.$n, "金额（元）");
			$objActSheet->setCellValue('I'.$n, "订单状态");
			
			$objActSheet->getStyle('B'.$n)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); 
			foreach($r as $row){
				$n++;
				$objActSheet->setCellValue('A'.$n,(string)$row->UUordernum);    
				$objActSheet->setCellValue('B'.$n, $row->UUltitle.$row->UUttitle);
				$objActSheet->setCellValue('C'.$n, (string)$row->UUordertime);    
				$objActSheet->setCellValue('D'.$n, (string)$row->UUdtime);    
				$objActSheet->setCellValue('E'.$n, (string)$row->UUordername." ".(string)$row->UUordertel);    
				$objActSheet->setCellValue('F'.$n, (string)$row->UUtprice/100);    
				$objActSheet->setCellValue('G'.$n, (string)$row->UUtnum);    
				$objActSheet->setCellValue('H'.$n, (string)$row->UUtotalmoney/100);    
				$objActSheet->setCellValue('I'.$n, strip_tags(OrderRecord::$UUstatusT[(string)$row->UUstatus]));    
				//输出样式
				$objActSheet->getStyle('B'.$n)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); 
			}
			$filename=date('Ymd').'产品报表汇总';
			break;
		/*分销账单汇总导出excel*/
		case "fsettle2Excel":
			$objActSheet->getColumnDimension('A')->setAutoSize(true); 
			$objActSheet->getColumnDimension('B')->setAutoSize(true);  
			$objActSheet->getColumnDimension('C')->setAutoSize(true);  
			$objActSheet->getColumnDimension('E')->setAutoSize(true);   
			$objActSheet->setCellValue('A'.$n, "产品所属");    
			$objActSheet->setCellValue('B'.$n, "订单总数");    
			$objActSheet->setCellValue('C'.$n, "总人数");    
			$objActSheet->setCellValue('D'.$n, "总金额");
			$objActSheet->getStyle('A'.$n)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); 
			foreach($summary as $lid=>$row){
				$n++;
				$objActSheet->setCellValue('A'.$n, $row['ltitle']);    
				$objActSheet->setCellValue('B'.$n, $row['order']);    
				$objActSheet->setCellValue('C'.$n, $row['tnum']);    
				$objActSheet->setCellValue('D'.$n, $row['money']/100);    
				//输出样式
				$objActSheet->getStyle('A'.$n)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); 
			}
			$filename=date('Ymd').'供应产品报表汇总';
			break;
		default:
			exit("未知生成excel路径");
		break;
	}
	$ua = $_SERVER['HTTP_USER_AGENT'];  
	if(preg_match('/MSIE/',$ua)){
		$filename = str_replace('+','%20',urlencode($filename));  
	}
	if(preg_match('/Mozilla\/5\.0\s\(Windows\sNT\s6\.[0-9];\sWOW64;\sTrident\/7\.0;\srv:11\.0\)\slike\sGecko/',$ua)){// IE 11
		$filename = str_replace('+','%20',urlencode($filename));  
	}
	 $filename.=".xls";
	 header("Content-Type: application/force-download");  
	 header("Content-Type: application/octet-stream");  
	 header("Content-Type: application/download");  
	 header("Content-Disposition:attachment;filename=$filename");  
	 header("Content-Transfer-Encoding: binary");  
	 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");  
	 header("Pragma: no-cache");  
	 $objWriter->save('php://output');
	 exit;
}
?>